import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

# 1.创建驱动对象
service = Service("C:/Program Files/Google/Chrome/Application/chromedriver.exe")
driver = webdriver.Chrome(service=service)

# 2.打开浏览器
driver.get("file:///C:/Users/82073/Desktop/pagetest/%E6%B3%A8%E5%86%8CA.html")

# 3.操作
# 1. 获取用户名输入框大小
print(driver.find_element(By.CSS_SELECTOR, "#userA").size)
# 2. 获取页面上第一个超链接的文本内容
print(driver.find_element(By.CSS_SELECTOR, "#fw").text)
# 3. 获取页面上第一个超链接的地址
print(driver.find_element(By.CSS_SELECTOR, "#fw").get_attribute("href"))
# 4. 判断页面中的 span 标签是否可见(在取消按钮旁边)
print(driver.find_element(By.CSS_SELECTOR, "span[name*='sp1']").is_displayed())
# 5. 判断页面中取消按钮是否可用
print(driver.find_element(By.CSS_SELECTOR, "#cancelA").is_enabled())
# 6. 判断页面中 ’旅游‘ 对应的 复选框 是否为选中状态
print(driver.find_element(By.CSS_SELECTOR, "#lyA").is_selected())

# 4.3s后关闭
time.sleep(3)

# 5.关闭驱动对象
driver.close()